#include "renderFrog.h"
#define SCALE 4

renderFrog::renderFrog(float init_red, float init_green, float init_blue)
{
	// Initialize the variables
	r = init_red; g = init_green; b = init_blue;
	// Load the texture!
	loadOpenGL2DTextureBMP("frog.bmp", &block_texture, GL_RGB);
}

renderFrog::~renderFrog(void)
{
}

// This draw method is intended to draw the shapes, set the material
// and appropriately texture the shapes generated.
// The frog has an additional timer in order to make it expand an contract
// while rendering. 
void renderFrog::draw(float init_x, float init_y, float init_z)
{

	// timer variables
	static float z_pusher = 0;
	static int Speed = 1;

	// Changes the z_pusher appropriately where the z_pusher
	// will determine the scale multiplier we will use on the
	// z-axis of the frog.
	z_pusher += 0.125 * Speed;
	if (z_pusher <= 0 || z_pusher >= (SCALE / 4))
	{
		Speed = -Speed;
	}

	x = (init_x) * SCALE;
	y = (init_y) * SCALE;
	z = ((init_z) * SCALE) + ( .4 * SCALE );

	//	/* Set up material properties. */
	GLfloat mat_ambient[] = { 1, 0.1, 0.1, 1 };
	GLfloat mat_diffuse[] = { 0.2, 0.2, 0.2, 1 };
	GLfloat mat_specular[] = { 0.8, 0.8, 0.8, 1 };

	glPushMatrix();

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, block_texture);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialf(GL_FRONT, GL_SHININESS, 10.0 ); /* No effect if specular == 0 */

	glTranslatef(x + (SCALE * 0.1), y + (SCALE * 0.1), z);
	glColor3f(r, g, b); 


	glScalef(1.0,1.0,1.0); // added to see walls and stuff
	glScalef(1.0, 1.0, z_pusher/(SCALE / 4));
	//START THE QUADS!
	glBegin(GL_QUADS);

	glNormal3f(0,0,-1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE*0.8, 0.0, 0.0);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE*0.8, SCALE*0.8, 0.0);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE*0.8, 0.0);

	glNormal3f(0,0,1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, SCALE*0.8);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE*0.8, 0.0, SCALE*0.8);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE*0.8, SCALE*0.8, SCALE*0.8);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE*0.8, SCALE*0.8);

	glNormal3f(-1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, SCALE*0.8);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE*0.8, 0.0, SCALE*0.8);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE*0.8, 0.0, 0.0);

	glNormal3f(1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE*0.8, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE*0.8, SCALE*0.8);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE*0.8, SCALE*0.8, SCALE*0.8);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE*0.8, SCALE*0.8, 0.0);

	glNormal3f(0,-1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE*0.8, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE*0.8, SCALE*0.8);
	glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 0.0, SCALE*0.8);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, 0.0, 0.0);

	glNormal3f(0,1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(SCALE*0.8, SCALE*0.8, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE*0.8, SCALE*0.8, SCALE*0.8);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE*0.8, 0.0, SCALE*0.8);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE*0.8, 0.0, 0.0);

	glEnd();
	glTranslatef(-x - (SCALE * 0.1), -y - (SCALE * 0.1), -z);
	glDisable(GL_TEXTURE_2D);

	glPopMatrix();

	//glPushMatrix();

	//glTranslatef(x + SCALE / 2, y + SCALE / 2, z);
	//glColor3f(1.0, 1.0, 1.0); 
	//
	////glScalef(0.5,0.5,0.5);

	//glEnable(GL_TEXTURE_2D);
	//glBindTexture(GL_TEXTURE_2D, block_texture);

	//glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	//glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	//glMaterialf(GL_FRONT, GL_SHININESS, 10.0 ); /* No effect if specular == 0 */

	//glRotatef(90, 1.0, 0.0, 0.0);
	//glTexCoord2f(0.0, 0.0);
	//glTexCoord2f(0.0, 1.0);
	//glTexCoord2f(1.0, 1.0);
	//glTexCoord2f(1.0, 0.0);
	//glutSolidSphere(SCALE/3, 12, 12);

	//glTranslatef(-x - SCALE / 2, -y - SCALE / 2, -z);

	//glDisable(GL_TEXTURE_2D);

	//glPopMatrix();
}